package com.huawei.petapp2.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.huawei.petapp2.R;
import com.huawei.petapp2.adapter.PetImageAdapter;
import com.huawei.petapp2.entity.ImageBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 宠物图片
 */
public class PetImageActivity extends AppCompatActivity {

    // 列表
    private RecyclerView mRecyclerView = null;

    // 列表数据
    private List<ImageBean> mItemData = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pet_image);
        // 初始化View
        initView();
    }

    /**
     * 初始化View
     */
    private void initView() {
        // 顶部返回
        ImageView mIvBack = findViewById(R.id.title_back);
        mIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 返回
                finish();
            }
        });

        mRecyclerView = findViewById(R.id.pet_image_item_recyclerView);
        // 设置列表数据
        initRecyclerData();
        // 初始化RecyclerView
        initRecyclerView();
    }

    /**
     * 设置列表数据
     */
    private void initRecyclerData() {
        mItemData.clear();
        ImageBean imageBean = new ImageBean("这是什么", R.drawable.ic_center_cat);
        mItemData.add(imageBean);
        ImageBean videoBean2 = new ImageBean("别挠我", R.drawable.ic_left_cat);
        mItemData.add(videoBean2);
        ImageBean videoBean3 = new ImageBean("我不服", R.drawable.ic_right_cat);
        mItemData.add(videoBean3);
    }

    /**
     * 初始化RecyclerView
     */
    private void initRecyclerView() {
        LinearLayoutManager manager = new LinearLayoutManager(PetImageActivity.this);
        //设置布局管理器
        mRecyclerView.setLayoutManager(manager);
        //设置为垂直布局，这也是默认的
        manager.setOrientation(RecyclerView.VERTICAL);
        //设置Adapter
        PetImageAdapter mPetImageAdapter = new PetImageAdapter(mItemData);
        mRecyclerView.setAdapter(mPetImageAdapter);
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    }



}